/*
 * DecoderManager.h
 *
 *  Created on: 2011-2-26
 *      Author: hao
 */

#ifndef DECODERMANAGER_H_
#define DECODERMANAGER_H_

#include <functional>
#include <vector>
#include <sys/mman.h>
#include <string>
#include "Decoder.h"
#include "automat.h"
#include "Error.h"
#include "StreamEnd.h"
#include "StreamOperationSlot.h"
#include "CueParser.h"

using namespace std;

class DecoderMaster {

    vector<Decoder *> vDecoder;

    StreamOperationSlot * pSlot;

public:

    DecoderMaster();

    ~DecoderMaster();

    void addDecoder(Decoder * pDecoder) {
        vDecoder.push_back(pDecoder);
    }
    
    void deleteDecoder( Decoder * pDecoder ){
        unsigned i;
        for( i = 0; i < vDecoder.size(); i++ ){
            if( vDecoder[i] == pDecoder )
                break;
        }
        
        vDecoder.erase( vDecoder.begin() + i );
    }
    
    void clearDecoder(){
        vDecoder.clear();
    }
    
    bool Seek( int index, int min, int second, int frame );

    bool Decoding( int index, void * pData, size_t length, size_t * pWriteLength);

    int SetupDecodingFile(void * pData, size_t length, unsigned * pchannel, unsigned * prate, unsigned * pformat ); //Return the decoder index of decoder

    int SetupDecodingTrack(void * pData, size_t length, unsigned * pchannel, unsigned * prate, unsigned * pformat, const CueSheet & sheet, unsigned TrackIndex); //Return the decoder index of decoder
    
    void getDecoderingFileTotalTime( int index, int * pMin, int * pSeconds, int * pFrame );

    std::string getSurportPrefixName();

};

#endif /* DECODERMANAGER_H_ */
